
package com.ami.kvm.jviewer.kvmpkts;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.math.BigDecimal;

import javax.swing.JOptionPane;

import com.ami.kvm.jviewer.gui.JVFrame;
import com.ami.kvm.jviewer.gui.JViewerApp;
import com.ami.kvm.jviewer.gui.JViewerView;
import com.ami.kvm.jviewer.gui.LocaleStrings;

class RCKeyListener extends KeyAdapter {
	public void keyPressed(KeyEvent paramKeyEvent) {
		JVFrame localJVFrame = JViewerApp.getInstance().getMainWindow();
		BigDecimal localBigDecimal1;
		BigDecimal localBigDecimal2;
		BigDecimal localBigDecimal3;
		if ((paramKeyEvent.getModifiersEx() & 0x200) != 512) {
			switch (paramKeyEvent.getKeyCode()) {
			case 61:
			case 107:
			case 521:
				if (Mousecaliberation.THRESHOLDFLAG) {
					JViewerView.ACCEL_THRESHOLD += 1;
				} else {
					localBigDecimal1 = new BigDecimal(JViewerView.MOUSE_ACCELERATION);
					localBigDecimal2 = new BigDecimal("1.0");
					localBigDecimal3 = localBigDecimal1.add(localBigDecimal2).setScale(2, 4);
					JViewerView.MOUSE_ACCELERATION = localBigDecimal3.floatValue();
				}
				paramKeyEvent.consume();
				Mousecaliberation.resetCursor();
				break;

			case 45:
			case 109:
				if (Mousecaliberation.THRESHOLDFLAG) {
					JViewerView.ACCEL_THRESHOLD -= 1;
					if (JViewerView.ACCEL_THRESHOLD <= 0) {
						JViewerView.ACCEL_THRESHOLD = 1;
						JOptionPane.showMessageDialog(localJVFrame, LocaleStrings.getString("3_9_MC"),
								LocaleStrings.getString("3_5_MC"), 1);
					}

				} else {
					localBigDecimal1 = new BigDecimal(JViewerView.MOUSE_ACCELERATION);
					localBigDecimal2 = new BigDecimal("1.0");
					localBigDecimal3 = localBigDecimal1.subtract(localBigDecimal2).setScale(2, 4);
					JViewerView.MOUSE_ACCELERATION = localBigDecimal3.floatValue();
					if (JViewerView.MOUSE_ACCELERATION <= 0.0F) {
						JOptionPane.showMessageDialog(localJVFrame, LocaleStrings.getString("3_10_MC"),
								LocaleStrings.getString("3_5_MC"), 1);

						JViewerView.MOUSE_ACCELERATION = 1.0F;
					}
				}
				paramKeyEvent.consume();
				Mousecaliberation.resetCursor();
			}

		}

		if ((paramKeyEvent.getModifiersEx() & 0x200) == 512) {
			if (!Mousecaliberation.THRESHOLDFLAG) {
				localBigDecimal1 = new BigDecimal(JViewerView.MOUSE_ACCELERATION);
				localBigDecimal2 = new BigDecimal("0.1");

				switch (paramKeyEvent.getKeyCode()) {
				case 107:
				case 521:
					localBigDecimal3 = localBigDecimal1.add(localBigDecimal2).setScale(2, 4);
					JViewerView.MOUSE_ACCELERATION = localBigDecimal3.floatValue();
					paramKeyEvent.consume();
					break;
				case 45:
				case 109:
					localBigDecimal3 = localBigDecimal1.subtract(localBigDecimal2).setScale(2, 4);

					JViewerView.MOUSE_ACCELERATION = localBigDecimal3.floatValue();

					if (JViewerView.MOUSE_ACCELERATION < 0.0F)
						JViewerView.MOUSE_ACCELERATION = 1.0F;
					paramKeyEvent.consume();
				}

				Mousecaliberation.resetCursor();
			}

			if ((JViewerApp.getInstance().isFullScreenMode()) || (JViewerApp.getInstance().isFullKeyboardEnabled())) {

				if (paramKeyEvent.getKeyCode() == 84) {
					if (JViewerApp.getInstance().GetRedirectionState() == JViewerApp.REDIR_STARTED) {
						if (!JViewerApp.getInstance().getJVMenu().getMenuSelected("Calibrate Mouse Threshold")
								.booleanValue()) {
							JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("Calibrate Mouse Threshold",
									true);
							JViewerApp.getInstance().getMousecaliberation().OnCalibareteMouseThreshold(true);
							JViewerApp.getInstance().getRCView().requestFocus();
						} else {
							JViewerApp.getInstance().getMousecaliberation().OnCalibareteMouseThreshold(false);
							JViewerApp.getInstance().getJVMenu().notifyMenuStateSelected("Calibrate Mouse Threshold",
									false);
							JViewerApp.getInstance().getRCView().requestFocus();
						}
					}
				}
				paramKeyEvent.consume();
			}
			return;
		}
	}
}
